<template>
  <div class="xxyl-div">
    <div class="header">
      <span class="title">{{ tagInfo.tagName }}</span>
      <span class="close" @click="emit('close')"></span>
    </div>
    <img
      class="loveImg"
      v-if="!props.info.clused"
      @click="changeClused('1')"
      src="/images/new/tag/love.png"
    />
    <img class="loveImg"  @click="changeClused('0')" v-else src="/images/new/tag/loved.png" />
    <div class="content-info" style="margin-top: 50px">
      <!-- 基础信息 -->
      <div class="header-box" style="margin-top: 30px">
        <span class="header-name">基础信息</span>
      </div>
      <div class="map-box" v-if="tagInfo.templatePic">
        <img class="img" :src="tagInfo.templatePic" />
      </div>
      <div class="table-box" style="margin-top: 20px">
        <el-form class="formInfo" label-width="90px">
          <el-form-item
            :label="item.key"
            v-for="item in infoItemList"
            :key="item.name"
          >
            <span class="form-item">{{ item.value }}</span>
          </el-form-item>
          <!-- <el-form-item label="地址">
            <span class="form-item">新港三号路与港医路交口</span>
          </el-form-item>
          <el-form-item label="开放时间">
            <span class="form-item">全天开放</span>
          </el-form-item> -->
          <!-- <div class="tag-box">
            <div class="tag" v-for="item in tagList" :key="item">{{item}}</div>
          </div> -->
        </el-form>
      </div>
      <div class="header-box" style="margin-top: 30px" v-if="false">
        <span class="header-name">周围红路灯（1km）</span>
      </div>
      <div class="table-box" style="height: 253px" v-if="false">
        <div class="hldbox">
          <p class="centerTitle">新港公园</p>
          <img class="img" src="/images/new/tag/hldbg.png" />
          <div class="randomBox parentr">
            <div
              class="randomitem childr"
              :class="{ one: item == '内涝', two: item == '垃圾堆放' }"
              v-for="(item, index) in ['占道经营', '内涝', '垃圾堆放']"
              :key="index"
            >
              {{ item.slice(0, 2) }}<br />
              {{ item.slice(2) }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import mapBox from "./map.vue";
const emit = defineEmits(["close","changeClose"]);
const props = defineProps({
  info: Object,
  isd: {
    default: false,
    type: Boolean,
  },
});


const changeClused = (clused) => {
  emit('changeClose', clused);
};

const torenderDom = () => {
  // 获取父元素和所有子元素
  const parent = document.querySelector(".parentr");
  const children = document.querySelectorAll(".childr");

  // 父元素和子元素的尺寸
  const parentWidth = parent.offsetWidth;
  const parentHeight = parent.offsetHeight;
  const childWidth = children[0].offsetWidth;
  const childHeight = children[0].offsetHeight;

  // 存储已放置子元素的位置
  const placedPositions = [];

  // 生成随机位置
  function getRandomPosition() {
    const maxX = parentWidth - childWidth; // 横坐标最大范围
    const maxY = parentHeight - childHeight; // 纵坐标最大范围
    return {
      x: Math.floor(Math.random() * maxX), // 随机横坐标
      y: Math.floor(Math.random() * maxY), // 随机纵坐标
    };
  }

  // 检测是否重叠
  function isOverlapping(newPos, placedPositions) {
    for (const pos of placedPositions) {
      if (
        newPos.x < pos.x + childWidth &&
        newPos.x + childWidth > pos.x &&
        newPos.y < pos.y + childHeight &&
        newPos.y + childHeight > pos.y
      ) {
        return true; // 重叠
      }
    }
    return false; // 不重叠
  }

  // 为每个子元素设置随机位置
  children.forEach((child) => {
    let newPos;
    let attempts = 0;
    const maxAttempts = 100; // 最大尝试次数，避免无限循环

    do {
      newPos = getRandomPosition(); // 生成随机位置
      attempts++;
      if (attempts > maxAttempts) {
        console.error("无法找到不重叠的位置");
        return;
      }
    } while (isOverlapping(newPos, placedPositions)); // 如果重叠，重新生成位置

    // 记录已放置的位置
    placedPositions.push(newPos);

    // 设置子元素的位置
    child.style.left = `${newPos.x}px`;
    child.style.top = `${newPos.y}px`;
  });
};

let tagInfo = ref({});
let tagList = ref([
  "盐碱地改造",
  "三季有花",
  "四季常绿",
  "绿化面积达5万平方米",
  "面积达87000平方米",
  "25种乔木",
  "共计1400余棵",
  "78种花灌木",
  "共计万余棵",
  "十余年历史",
]);

let infoItemList = ref([]);
const getData = () => {
  useApi
    .post("/dynamicview/ar/tagDetail", { tagId: props.info.tagId })
    .then((res) => {
      tagInfo.value = res.data.tagInfo;
      infoItemList.value = JSON.parse(res.data.tagInfo.templateCapture) || [];
      // state.pm = res.data.tagInfo
      // state.data1 = res.data.faceStats
      // state.data2 = res.data.vehicleStats
      // state.data3 = res.data.tempCapture
      // if (state.pm.templateId == 'TCC') {
      //   getEvent()
      //   getEvent4()
      // }
      // if (state.pm.templateId == 'CBTKQ') {
      //   getEvent1()
      // }
      // if (state.pm.templateId == 'JYXF') {
      //   getEvent2()
      // }
      // if (state.pm.templateId == 'BGQ') {
      //   getEvent3()
      // }
      // if (state.pm.templateId == 'CBTKQ' || state.pm.templateId == 'JMQ') {
      //   setTimeout(() => {
      //     state.pm.templateId == 'CBTKQ' ? chart3() : chart4()
      //   }, 1000);
      // }
      //   torenderDom();
    });
};

watch(
  () => props.info,
  (newval) => {
    if (newval.tagId) {
      getData();
    }
  },
  {
    deep: true,
    immediate: true,
  }
);

onMounted(() => {});
</script>

<style lang="scss">
.xxyl-div {
  width: 503px;
  max-height: 720px;
  background: url("/images/new/tag/tagbg.png") no-repeat;
  background-size: 100% 100%;
  position: relative;
  padding-bottom: 30px;
  .loveImg {
    width: 40px;
    height: 40px;
    position: absolute;
    right: 40px;
    top: 75px;
    cursor: pointer;
     z-index: 999;
  }
  .header {
    width: 100%;
    height: 52.5px;
    position: relative;
    background: url("/images/new/tag/header.png") no-repeat;
    background-size: 100% 100%;
    .title {
      display: inline-block;
      height: 100%;
      padding-left: 25px;
      font-family: YouSheBiaoTiHei;
      font-size: 25px;
      color: #ffffff;
      line-height: 60px;
    }

    .close {
      width: 40px;
      height: 40px;
      position: absolute;
      right: 16px;
      top: 20.5px;
      line-height: 40px;
      text-align: center;
      color: #fff;
      font-size: 30px;
      cursor: pointer;
    }
  }
  .tab-content {
    margin: 23px 10px 10px 33px;
    width: 366px;
    height: 40px;
    background: url("/images/new/tag/tabbg.png") no-repeat;
    background-size: 100% 100%;
    display: flex;
    align-items: center;
    padding: 2px 4px;
    position: relative;
    .tab-btn {
      width: 115px;
      height: 100%;
      text-align: center;
      line-height: 36px;
      font-family: YouSheBiaoTiHei;
      font-size: 21px;
      color: #ffffff;
      cursor: pointer;
      &.active {
        background: url("/images/new/tag/tab.png") no-repeat;
        background-size: 100% 100%;
      }
    }
  }

  .content-info {
    padding: 0 30px;
    .table-box {
      width: 100%;
      max-height: 300px;
      overflow: auto;
      background: url("/images/new/tag/tablebg.png") no-repeat;
      background-size: 100% 100%;
      .formInfo {
        width: 100%;
        max-height: 300px;
        padding: 20px 20px 20px 20px;
        .el-form-item {
          margin-bottom: 10px;
        }
        .el-form-item__label {
          font-family: PingFangSC, PingFang SC;
          font-size: 18px;
          color: #ffffff;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .form-item {
          width: 100%;
          text-align: right;
          font-family: PingFangSC, PingFang SC;
          font-size: 18px;
          color: #ffffff;
        }
        .tag-box {
          margin-top: 12px;
          display: flex;
          align-items: top;
          flex-wrap: wrap;
          gap: 4px;
          .tag {
            font-family: PingFangSC, PingFang SC;
            font-size: 16px;
            color: #ffffff;
            height: 36px;
            text-align: center;
            padding: 0 10px;
            line-height: 36px;
            // background: url("/images/new/tag/tagbg.png") no-repeat;
            // background-size: 100% 100%;
            background: rgba(69, 192, 255, 0.5);
          }
        }
      }
    }
    .map-box {
      width: 100%;
      height: 248px;
      .img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>

<style lang="scss">
.xxyl-div {
  .video-box {
    width: 440px;
    height: 247.5px;
  }
  .el-select__wrapper {
    background: #067cc0;
    span {
      color: #ffffff !important;
    }
  }
  .el-tabs__item {
    font-family: YouSheBiaoTiHei;
    font-size: 21px;
    color: #ffffff;
    line-height: 29px;
    text-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
    &.is-active {
    }
  }
  .el-tabs__nav-wrap:after {
    background: none;
  }
  .el-tabs__active-bar {
    background: #18e1ff;
  }
  .header-box {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .header-name {
      font-family: YouSheBiaoTiHei;
      font-size: 21px;
      color: #ffffff;
    }
  }
  .table-box {
    margin-top: 15px;
    width: 100%;
    background: url("/images/new/tag/tablebg.png") no-repeat;
    background-size: 100% 100%;
    .header-t {
      display: flex;
      align-items: center;
      width: 100%;
      height: 40px;
      background: url("/images/new/tag/headerbg.png") no-repeat;
      background-size: 100% 100%;
      color: #fff;
      .ht {
        height: 100%;
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 18px;
        color: #ffffff;
        line-height: 40px;
        margin: 16px 2px;
        &:nth-child(1) {
          padding-left: 20px;
        }
        &:nth-child(1) {
          width: 100px;
        }
        &:nth-child(2) {
          width: 100px;
        }
        &:nth-child(3) {
          flex: 1;
        }
        &:nth-child(4) {
          width: 100px;
        }
      }
    }
    .table-cell-box {
      width: 100%;
      height: 175px;
      overflow: auto;
      .cell-p {
        height: 50px;
        display: flex;
        align-items: center;
        overflow: hidden;
        margin: 8px 0;
        .cell {
          height: 100%;
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 18px;
          color: #ffffff;
          line-height: 50px;
          margin: 16px 2px;
          word-wrap: break-word; /* 长单词换行 */
          overflow-wrap: break-word; /* 推荐使用 */
          word-break: break-all; /* 强制在任意字符间换行 */
          white-space: normal; /* 默认换行行为 */
          // padding-left:12px;
          &:nth-child(1) {
            width: 100px;
            text-align: center;
            .img {
              width: 85px;
              height: 47.5px;
            }
          }
          &:nth-child(2) {
            width: 100px;
          }
          &:nth-child(3) {
            flex: 1;
            white-space: nowrap; /* 禁止换行 */
            overflow: hidden; /* 隐藏溢出内容 */
            text-overflow: ellipsis; /* 超出用省略号表示 */
          }
          &:nth-child(4) {
            width: 100px;
          }
        }
      }
    }
  }
  .echarts-box {
    height: 215px;
  }
  .info-box {
    padding: 13px;
    font-family: PingFangSC, PingFang SC;
    font-size: 18px;
    color: #ffffff;
    p {
      margin: 0;
      font-family: PingFangSC, PingFang SC;
      font-size: 18px;
      color: #ffffff;
      line-height: 27px;
      display: flex;
      align-items: center;
      .icon {
        border-radius: 50%;
        width: 9px;
        height: 9px;
        background: #88d4ff;
        margin-right: 15px;
      }
    }
  }
  .hldbox {
    height: 100%;
    box-shadow: inset 0px 0px 60px 0px #45c0ff;
    border: 1px solid;
    border-image: linear-gradient(
        360deg,
        rgba(62, 176, 255, 1),
        rgba(255, 255, 255, 1)
      )
      1 1;
    position: relative;
    .centerTitle {
      position: absolute;
      top: 42%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-family: PingFangSC, PingFang SC;
      font-weight: 600;
      font-size: 16px;
      color: #ffffff;
      z-index: 2;
    }
    .img {
      width: 204px;
      height: 204px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
    .randomBox {
      width: 204px;
      height: 204px;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      .randomitem {
        width: 60px;
        height: 60px;
        position: absolute;
        background: url("/images/new/tag/iconbg1.png") no-repeat;
        background-size: 100% 100%;
        text-align: center;
        line-height: 18px;
        font-family: PingFangSC, PingFang SC;
        font-size: 16px;
        color: #ffffff;
        padding: 10px 0;
        &.one {
          padding: 20px 0;
          background: url("/images/new/tag/iconbg2.png") no-repeat;
          background-size: 100% 100%;
        }
        &.two {
          background: url("/images/new/tag/iconbg3.png") no-repeat;
          background-size: 100% 100%;
        }
        &:nth-child(1) {
          left: 70px;
          top: -15px;
        }
        &:nth-child(2) {
          left: -15px;
          top: 75px;
        }
        &:nth-child(3) {
          right: -15px;
          top: 65px;
        }
        &:nth-child(4) {
          left: 40px;
          bottom: -15px;
        }
      }
    }
  }
}
</style>